package com.shenmazong.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Qi
 * @version 1.0
 * @description TODO
 * @date 2021/9/28 8:57
 */
@Configuration
public class MqConfig {

    public static final String THEORY_QUEUE = "theoryQueue";
    public static final String THEORY_EXCHANGE = "theoryExchange";

    public static final String TASK_LAYOUT_QUEUE = "taskLayoutQueue";
    public static final String TASK_LAYOUT_EXCHANGE = "taskLayoutExchange";

    public static final String TASK_SUBMIT_QUEUE = "taskSubmitQueue";
    public static final String TASK_SUBMIT_EXCHANGE = "taskSubmitExchange";

    public static final String TASK_START_TEST_QUEUE = "taskStartTestQueue";
    public static final String TASK_START_TEST_EXCHANGE = "taskStartTestExchange";

    public static final String SET_TASK_TEST_START_QUEUE = "setTaskTestStartQueue";
    public static final String SET_TASK_TEST_START_EXCHANGE = "setTaskTestStartExchange";

    public static final String SET_TASK_TEST_END_QUEUE = "setTaskTestEndQueue";
    public static final String TASK_START_END_EXCHANGE = "setTaskTestEndExchange";

    //理论库同步队列
    @Bean
    public Queue theoryToEsQueue(){
        return  new Queue(THEORY_QUEUE,true);
    }

    @Bean
    public DirectExchange theoryExchange(){
        return  new DirectExchange(THEORY_EXCHANGE);
    }

    @Bean
    public Binding theoryExchangeBinding(){
        return  BindingBuilder.bind(theoryToEsQueue()).to(theoryExchange()).with("");
    }

    //考试安排展示队列
    @Bean
    public Queue layoutToRedisQueue(){
        return  new Queue(TASK_LAYOUT_QUEUE,true);
    }

    @Bean
    public DirectExchange layoutToRedisExchange(){
        return  new DirectExchange(TASK_LAYOUT_EXCHANGE);
    }

    @Bean
    public Binding layoutToRedisExchangeBinding(){
        return  BindingBuilder.bind(layoutToRedisQueue()).to(layoutToRedisExchange()).with("");
    }

    //考试提交内容接收自动判卷队列
    @Bean
    public Queue taskSubmitQueue(){
        return  new Queue(TASK_SUBMIT_QUEUE,true);
    }

    @Bean
    public DirectExchange taskSubmitExchange(){
        return  new DirectExchange(TASK_SUBMIT_EXCHANGE);
    }

    @Bean
    public Binding taskSubmitExchangeBinding(){
        return  BindingBuilder.bind(taskSubmitQueue()).to(taskSubmitExchange()).with("");
    }

    //开始作业考试队列
    @Bean
    public Queue taskStartTestQueue(){
        return  new Queue(TASK_START_TEST_QUEUE,true);
    }

    @Bean
    public DirectExchange taskStartTestExchange(){
        return  new DirectExchange(TASK_START_TEST_EXCHANGE);
    }

    @Bean
    public Binding taskStartTestExchangeBinding(){
        return  BindingBuilder.bind(taskStartTestQueue()).to(taskStartTestExchange()).with("");
    }

    //设置作业开始的队列
    @Bean
    public Queue setTaskTestStartQueue(){
        return  new Queue(SET_TASK_TEST_START_QUEUE,true);
    }

    @Bean
    public DirectExchange setTaskTestStartExchange(){
        return  new DirectExchange(SET_TASK_TEST_START_EXCHANGE);
    }

    @Bean
    public Binding setTaskTestStartExchangeBinding(){
        return  BindingBuilder.bind(setTaskTestStartQueue()).to(setTaskTestStartExchange()).with("");
    }

    //设置作业结束的队列
    @Bean
    public Queue setTaskTestEndQueue(){
        return  new Queue(SET_TASK_TEST_END_QUEUE,true);
    }

    @Bean
    public DirectExchange setTaskTestEndExchange(){
        return  new DirectExchange(TASK_START_END_EXCHANGE);
    }

    @Bean
    public Binding setTaskTestEndExchangeBinding(){
        return  BindingBuilder.bind(setTaskTestEndQueue()).to(setTaskTestEndExchange()).with("");
    }

}
